<?php

	/*
		Voodoo Validator
		www.voodoovalidator.com
	*/
	
	/*
		For help: admin@voodoovalidator.com
	*/
	
	/*
		This application was developed originally by 
		Robbie Vasquez - www.robbievasquez.com
		Casey McLaughlin - www.caseymclaughlin.com
	*/
	
	/*
		BIRTHDAY: June 1st, 2009
		LAST MODIFIED: 08/12/2010
		BY: Robbie Vasquez
	*/

//===========================================================

	// The $_GET variable 'dir' comes from validate_start.js at the beginning
	// and then validate_continue_script.php for directories within the root directories.
	// It is the full path to the directory from the root (excluding the root itself)
	// including the name of the directory.
	$path = $_GET['dir'];


	// This is the root on the server to the website
	// 'http://examples.com' will not work
	// You need the exact root.
	// For examples, a Linux Ubuntu server would need this:
	// $root = '/var/www/example/';
	$root = '' . $path;


	// These two arrays will fill this web page with
	// directories in the root of the website and
	// files in the root of the website.
	$dirs = array();
	$files = array();


	// Open the root directory
	$parts = opendir($root);


	// This array sets up whatever directories you want to ignore.
	// For example, if would be a waste of time to validate an 'image' folder
	// and a word document folder.
	// For example: $ignore = array('images', 'docs')
	$ignore = array('images', '.', '..', 'voodoo_images', 'voodoo_scripts');


	// A while loop to get all directories and files into their respective arrays
	while($content = readdir($parts))
	{
		// If it's not something you want to ignore...
		if(!in_array($content, $ignore))
		{
			// The file type will help decide which array the piece belongs in
			$filetype = filetype($root . '/' . $content);
			
			if($filetype == 'dir')
				$dirs[] = $content;
			else
				$files[] = $content;
		}
	}


	// $sans_slash is the variable $path with the '/' marks removed.
	// Since the $path was needed in certain parts of the elements,
	// the '/' marks were breaking the system.
	// Removing them keeps unique values where needed
	// but does not affect the next pathway for clicked directories.
	$sans_slash = str_replace('/', '', $path);
	

	// 'validate_continue_script.php' is a script file that activates when this page loads.
	// <li> elements with class 'file' are processed through the validating file,
	// validate_w3c_v4.php, with guidance from validate_continue_script.php
	// and new directories will be set up and ready to by opened on click.
	require('validate_continue_script.php');


	// The <h3> element that was clicked on will disappear,
	// so this will print a new one.
	echo '<h3 class="close_' . $sans_slash . '" id="' . $sans_slash . '" alt="' . $previous . '"><span class="fakelink">&plusmn; ' . $path . '</span></h3>';


	// Just starts the unordered list for more directories and files
	echo '<ul id="validator_list">';


	// This foreach loop prints all the parts of the directory array
	// so that the script validate_continue_script.php has everything it needs.
	// All classes and id's are important.
	// If you want to change them here, they must be changed in validate_continue_script.php to match
	foreach($dirs as $dir) 
		echo '<li id="' . $sans_slash . $dir . '"><h3 class="directory_' . $sans_slash . '" id="' . $dir . '"><span class="fakelink">&raquo; ' . $dir . '</span></h3></li>';


	// This foreach loop prints all the parts of the files array
	// so that the script validate_continue_script.php has everything it needs
	// to send the files through the validating file, validate_w3c_v4.php
	// All the classes and id's are important.
	// If you want to change them here, they must be changed in validate_continue_script.php to match
	foreach($files as $file)
		echo '<li class="file" id="' . $file . '">' . $file . '<br/><img src="/images/loadbar.gif" alt="loading..." /></li>';


	echo '</ul>';


/* EOF */